# -*- coding: utf-8 -*-
#  @author  Bink
#  @date  2020/9/2 20:03
# @Email : 2641032316@qq.com

import numpy as np
import pandas as pd
import time, datetime

pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth', 100)

# file_dorm = pd.read_table("D:/pra/Python/python-programming-project/src/resources/train/1.txt",
file_dorm = pd.read_table("D:/pra/Python/python-programming-project/src/resources/train/dorm_train.txt",
                          dtype=str,                          delimiter=','
                          )
df_dorm = pd.DataFrame(file_dorm)
df_dorm.columns = ['学生id', '具体时间', '进出方向(0进寝室，1出寝室)']

df_dorm['具体时间'] = (df_dorm['具体时间'].apply(lambda x:
                                         int(time.mktime(time.strptime(x, "%Y/%m/%d %H:%M:%S")))
                                         )
                   # *
                   # df_dorm['进出方向(0进寝室，1出寝室)'].apply(lambda x:
                   #                                  -1 if int(x) == 0
                   #                                  else
                   #                                  1
                   #                                  )
                   )

# df_dorm = df_dorm.iloc[:, :-1]

# print(df_dorm.groupby('学生id'))
df_dorm2 = df_dorm.groupby('学生id').count().reset_index()['具体时间']
# df_dorm = df_dorm.groupby('学生id').sum().reset_index()
# df_dorm['具体时间'] = df_dorm['具体时间'].apply(lambda timeStamp:
#                                         time.strftime("%Y--%m--%d %H:%M:%S", time.localtime(timeStamp))
#                                         )
# df_dorm['进出次数'] = df_dorm2
df_dorm2 = df_dorm.groupby('学生id').count().reset_index()['学生id']
# df_dorm.to_excel("./out/dormInfo.xlsx", index=None)
# print(df_dorm)
# print(df_dorm2)
# print(type(df_dorm))
df_dorm['学生id'].astype(int)
df_dorm3 = df_dorm.set_index(['学生id', '具体时间'])['进出方向(0进寝室，1出寝室)'].sort_index()
print(df_dorm3.shape)
# df_dorm3 = df_dorm.set_index(['学生id', '进出方向(0进寝室，1出寝室)'])['具体时间'].sort_index()
df_dorm3[:1000000].to_excel("./out/dormInfoSorted1.xlsx")
df_dorm3[1000000:2000000].to_excel("./out/dormInfoSorted2.xlsx")
df_dorm3[2000000:].to_excel("./out/dormInfoSorted3.xlsx")
# print(df_dorm3)
